package com.oscar.ehome.view.pageview.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.oscar.ehome.R;
import com.oscar.ehome.bean.pagebean.PageAppBean;
import com.oscar.ehome.utils.system.SystemConfigFactory;

import java.util.List;

/**
 * Created by oscar
 * author: MengWanhe
 * date: On 2017/6/28
 * 应用展示
 */

public class PagesAdapter extends BaseAdapter {

    private List<String> specailList;
    int colnum = 1;
    private LayoutInflater mInflater;
    private Context mContext = null;
    int size;
    public PagesAdapter(Context context, int colnum, List<String> list ,int size) {
        this.mContext = context;
        this.colnum = colnum;
        this.specailList = list;
        this.size=size;
        mInflater = LayoutInflater.from(context);
    }

    public void setList(List<String> list,int size) {
        this.specailList = list;
        this.size=size;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        Log.e("zuihou", "updateAdapterssss: "+size);

        if(size<4){
            return size+1;
        }else{
            return colnum;
        }
//        if (specailList.size() < colnum) {
//            return specailList.size();
//        }

    }

    @Override
    public Object getItem(int position) {
        return specailList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.adpter_page, null);
            holder = new ViewHolder();
            holder.applText = (TextView) convertView.findViewById(R.id.appl_text);
            holder.applLayout = (LinearLayout) convertView.findViewById(R.id.appl_layout);
            holder.applImg = (ImageView) convertView.findViewById(R.id.appl_img);
            holder.pageapplation_view = convertView.findViewById(R.id.pageapplation_view);
            convertView.setTag(holder); //
        } else {
            holder = (ViewHolder) convertView.getTag(); //
        }

        if (specailList.size() > 0) {
            if (position == size) {
                holder.applImg.setImageResource(R.mipmap.guanli);
                holder.applText.setText("更多");
                holder.pageapplation_view.setVisibility(View.GONE);
            } else {
                String stats = specailList.get(position);
                holder.pageapplation_view.setVisibility(View.VISIBLE);
                switch (stats) {
                    case "8"://应用中心
                        holder.applImg.setImageResource(R.mipmap.yyzx);
                        holder.applText.setText(R.string.yyzx);
                        break;
                    case "7"://考勤签到
                        holder.applImg.setImageResource(R.mipmap.indexqian);
                        holder.applText.setText(R.string.kqqd);
                        break;
                    case "6"://统计
                        holder.applImg.setImageResource(R.mipmap.indextongji);
                        holder.applText.setText(R.string.tj);
                        break;
                    case "9"://准会员
                        holder.applImg.setImageResource(R.mipmap.huiyuan);
                        holder.applText.setText(R.string.zhy);
                        break;
                    case "4"://学习管理
                        holder.applImg.setImageResource(R.mipmap.xuexi);
                        holder.applText.setText(R.string.study);
                        break;
                    case "3"://活动管理
                        holder.applImg.setImageResource(R.mipmap.huodong);
                        holder.applText.setText(R.string.hd);
                        break;
                    case "11"://寿险通
                        holder.applImg.setImageResource(R.mipmap.sxt);
                        holder.applText.setText(R.string.sxt);
                        break;
                    case "10"://掌中宝
                        holder.applImg.setImageResource(R.mipmap.zzb);
                        holder.applText.setText(R.string.zzb);
                        break;
                    case "12"://保险档案
                        holder.applImg.setImageResource(R.mipmap.dangan1);
                        holder.applText.setText(R.string.insurance_text);
                        break;
                    case "13"://工作日志
                        holder.applImg.setImageResource(R.mipmap.jilu);
                        holder.applText.setText(R.string.log_text);
                        break;
                    case "14"://工作日志
                        holder.applImg.setImageResource(R.mipmap.zhagnzhishi);
                        holder.applText.setText(R.string.know_text);
                        break;
                    case "15"://获客
                        holder.applImg.setImageResource(R.mipmap.huoke);
                        holder.applText.setText(R.string.huoke);
                        break;
                    case "16"://考勤签到
                        holder.applImg.setImageResource(R.mipmap.indexqian);
                        holder.applText.setText(R.string.kqqd);
                        break;
                    case "17"://dudao
                        holder.applImg.setImageResource(R.mipmap.dudaowang);
                        holder.applText.setText(R.string.dudao);
                        break;
                    case "18"://nimingjubao
                        holder.applImg.setImageResource(R.mipmap.nimingjubao);
                        holder.applText.setText(R.string.nimingjubao);
                        break;
                    case "19"://nimingjubao
                        holder.applImg.setImageResource(R.mipmap.mingpian);
                        holder.applText.setText(R.string.yaoqinghan);
                        break;
                    case "20"://nimingjubao
                        holder.applImg.setImageResource(R.mipmap.youxi);
                        holder.applText.setText(R.string.youxi);
                        break;
                    case "21":
                        holder.applImg.setImageResource(R.mipmap.tuoguan);
                        holder.applText.setText(R.string.baodantuoguan);
                        break;
                    case "22":
                        holder.applImg.setImageResource(R.mipmap.yejichaxun);
                        holder.applText.setText(R.string.yejichaxun);
                        break;
                }
            }
        }
        return convertView;
    }

    class ViewHolder {
        TextView applText;
        LinearLayout applLayout;
        ImageView applImg;
        View pageapplation_view;
    }

}
